lst=[]

for i in range(5):
    goods=input('输入商品编号及名称:')
    lst.append(goods)

for item in lst:
    print(item)

cart=[]

while True:
    flag = False
    num = input('请输入商品编号')
    for item in lst:
        if num == item[0:4]:
            print('商品已加入购物车')
            flag=True
            cart.append(item)
            break

    if not flag and num != 'q':
        print('商品不存在')
    if num == 'q':
        break
print('*' * 50)
cart.reverse()
print(cart)
